<h3>Pharmacy Registration</h3>
<div id="popup_top"></div> 
<div id="popup_mid"> 
	<?php echo $form->create('Pharmacy',array('action'=>'register','class'=>'splashForm','id'=>'pharmacyReg'));?>
	<table border="0" cellspacing="0" cellpadding="0">
	        <tr>
	            <td><?php echo $form->input('Username',array('label'=>false,'div'=>'', 'value'=>'Username')); ?></td>
	        </tr>
	        <tr><td>
	        	<input type="text" name="Pharmacyfakepassword" id="Pharmacyfakepassword" value="Password" onfocus="pwdFocus()" />
	        	<?php echo $form->password('Password',array('label'=>false,'div'=>'', 'style'=>'display:none;')); ?>
	        </td></tr>
	        <tr><td><?php echo $form->input('Email',array('label'=>false,'div'=>'', 'value'=>'Email')); ?></td></tr>
	        <tr><td><input type="button" value="Register" class="pharmacyBtn" /></td></tr>
	</table>
	<?php 
	    echo $form->end();
	?>
	<div style="clear:both;"></div>
</div>
<div id="popup_bottom"></div> 
<script>

	function pwdFocus() {
	    $('#Pharmacyfakepassword').hide();
	    $('#PharmacyPassword').show();
	    $('#PharmacyPassword').focus();
	}
	
	function v_fRemoveErrors()
	{
		$('#PharmacyUsername').focus(function(){
	         $('#PharmacyUsername').parent().find('span').remove();
	         if ( $(this).val() == "Username" )
		         $(this).val('');
	    });
	    
	    $('#PharmacyPassword').focus(function(){
	         $('#PharmacyPassword').parent().find('span').remove();
	    });
	    
	    $('#PharmacyEmail').focus(function(){
	         $('#PharmacyEmail').parent().find('span').remove();
			 if ( $(this).val() == "Email" )
	         	$(this).val('');
	    });
	}
	
	function v_fValidate()
    {
    	var Username = $('#PharmacyUsername').val();
    	if( Username == "" || Username == "Username" ){
        	alert('Please enter Username');
        	$('#PharmacyUsername').focus();
        	return false;
    	}
    	var Password = $('#PharmacyPassword').val();
    	if( Password == "" ){
        	alert('Please enter Password');
        	pwdFocus();
        	return false;
    	}
    	var Email = $('#PharmacyEmail').val();
    	if( Email == "" || Email == "Email" ){
        	alert('Please enter Email');
        	$('#PharmacyEmail').focus();
        	return false;
    	}
    	return true;
    }
    
    $(document).ready(function(){
       
    	v_fRemoveErrors();
       $('.pharmacyBtn').click(function(){
    	   if ( !v_fValidate())
        	   return false;
           $.ajax({
                type: 'POST',
                url: 'pharmacies/save',
                data:$('form#pharmacyReg').serializeArray(),
                dataType: 'json',
                success: function(data){ 
                    if(data.success == 'faild')
                    {
                        if(data.Username)
                        {
                        	$('#PharmacyUsername').parent().find('span').remove();
                            $('#PharmacyUsername').parent().prepend('<span class="error" style="float:left;color:red">'+data.Username+'</span>');
                        }
                        
                        if(data.Password)
                        {
                        	$('#PharmacyPassword').parent().find('span').remove();
                            $('#PharmacyPassword').parent().prepend('<span class="error" style="float:left;color:red">'+data.Password + '</span>');
                        }
                        
                        if(data.Email)
                        {
                        	$('#PharmacyEmail').parent().find('span').remove();
                            $('#PharmacyEmail').parent().prepend('<span class="error" style="float:left;color:red">'+data.Email+'</span>');
                        }
                    }
                    else
                    {
						 jAlert(data, 'Message');

                         $('#PharmacyUsername').val('');
                         $('#PharmacyPassword').val('');
                         $('#PharmacyEmail').val('');
                        $('#modalOne').hide();
                        $('.lb_overlay').remove();
                       
                    }
                },
                error: function(message){
							 jAlert('Network connection errors', 'Message');
                }
                });
       });
    });
</script>